<?php /*
@session_start();
 if((!isset($_SESSION["kt_login_id"]) && !isset($_SESSION["kt_login_user"]) &&  !isset($_SESSION["kt_login_level"])) ) {

    header("Location: login.php");
    exit;
	
}else{

$level = addslashes($_SESSION['kt_login_user']);
$user = addslashes($_SESSION['kt_login_level']);

echo $level;
echo $user;
}*/

require_once("classes/respondent.class.php");
require_once("classes/newsletter.class.php");
require_once("classes/util/utilitarios.class.php");


//Instanciando Objetos
$respondent 	= new Respondent();
$utilitario 	= new Util();

//Ids para envio dos emails
foreach($_POST as $nome_campo => $valor)
{ 
	if($valor!='Send Data'){
		if($nome_campo=='newsletter'){
			$valorNewsletter[$nome_campo] =$valor;
		}else{
			$valorUids[$nome_campo] = $valor;
		}
	}
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/user2.dwt.php" codeOutsideHTMLIsLocked="false" --><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>QS Controller</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEditableHeadTag -->
<!-- InstanceEndEditable -->
<style type="text/css" media="all">
<!--
@import url("css/basics.css");
-->
</style>
<!-- TinyMCE -->
<script type="text/javascript" src="includes/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript"
   src="includes/tiny_mce/plugins/tinybrowser/tb_tinymce.js.php"></script>
<script type="text/javascript">
	tinyMCE.init({
		// General options
    	mode : "textareas",
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
theme_advanced_buttons1:
"code,bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,cleanup,link,unlink,image,table",

		// Theme options
		theme_advanced_buttons2 : "formatselect,fontselect,fontsizeselect,forecolor,backcolor,fullscreen",
		theme_advanced_buttons3 : "",
		theme_advanced_buttons4 : "",


		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,

		// Example content CSS (should be your site CSS)
	 content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",
    file_browser_callback : "tinyBrowser",
		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
</script>
<!-- /TinyMCE -->

</head>
<body>
<div id="box">
<div id="topo">
<span>
<img src="images/logo.png" alt="QS Controller" width="293" height="112"  />
</span>
<p>Version: 1.0</p>
<p>Status: Beta </p>
<p><!-- InstanceBeginEditable name="logout" -->logout<!-- InstanceEndEditable --></p>

</div><!-- end div topo-->
<div id="menuhorizontal">
  <table width="500" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td><a href="index.php">Home</a></td>
       <td><a href="registered.php">People</a></td>
        <td><a href="newsletterList.php">Newsletter</a></td>
        
      <td><a href="statistics.php">Statistics</a></td>
    </tr>
  </table>


</div><!-- end div menuhorizontal -->

<div id="content">
<!-- InstanceBeginEditable name="content" -->  
<div id="menudiv" >
<?php
$utilitario->menu('newsletter');
?>
</div><!-- end div submenu -->
	<div class="KT_tng" >
      <h1> DIRECT MAIL - Send</h1>
      <div class="msgerror" id="msgerror">
      <?php 
	  
	  
	  ?>
      </div>
	  <table class="listTable">
	  <tr><th>NAME</th><th>EMAIL</th><th>STATUS</th></tr>
	  <?php
	  //Exibindo resultado do envio
	  	foreach($valorUids as $registros){
		//pegando dados do destinatário
		$respondentValor = $respondent->searchObject($registros);
		
		$respondentInfo = mysql_fetch_assoc($respondentValor );
		//chamando metodo de envio
		$sendit = $utilitario->sendMail($valorNewsletter['newsletter'],$respondentInfo['EMAIL']);

		
	    if (($i % 2) == 1){ 
		   	$fundo="#FEFEFE"; 
		  }else{ 
		  	$fundo="#CDCDCD"; 
		  }
			$i++;
			echo "<tr bgcolor=$fundo>\n";
		    echo "<td>".$respondentInfo['NAME']."</td><td>".$respondentInfo['EMAIL']."</td><td>".$sendit."</td>";
			echo "</tr>\n";
		}
	  
	  
	  
	  ?>
</table>

      </div><!-- InstanceEndEditable -->
</div><!-- end div content -->
</div> <!-- end div box -->

</body>
<!-- InstanceEnd --></html>
